@extends('home.layout.base')
@section('title', '个人中心')
@section('pluginstyle')
<script src="{{ asset('/dist/home/js/1102.js') }}"></script>
<link rel="stylesheet" type="text/css" href="{{ asset('/dist/home/css/css.css') }}" />
<style type="text/css">
    .addr{
        /*border: 1px red solid;*/
        width:400px;
    }
    .edde{
        /*border: 1px green solid;*/
        width:100px;
        float: right;
        margin-top:-23px;
        margin-left: -300px;
    }
    .sai{
        height: 10px;
    }
    #del{
        cursor:pointer;
    }
    .shou{
        cursor:pointer;
    }
    #error{
        float: left;
        margin-bottom: 600px;
        /*margin-right: 1000px;*/
    }
</style>
<link rel="stylesheet" href="{{ asset('/dist/home/css/qikoo_user.css') }}">
<script>var _isindex = 0;</script>
@endsection
@section('content')
<div class="user-body">
    <div class="user-container">
        <div class="user-crumbs m-b-10">
            <a href="{{ url('/user') }}">首页</a> > 收货地址
        </div>
        <div class="clearfix_new">
            @include('home.user.menu')
            <div class="shade_content" style="display:none">
                <div class="col-xs-12 shade_colse">
                    <button onclick="javascript:onclick_close();">x</button>
                </div>
                <div class="nav shade_content_div">
                    <div class="col-xs-12 shade_title">
                        新增收货地址
                    </div>
                    <div class="col-xs-12 shade_from">
                        <form action="{{ url('/address/add') }}" method="post">
                            <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
                            <div class="col-xs-12">
                                <span class="span_style" id="" style="margin-right: 28px;">地&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;区</span>
                                <div class="city_2">
                                    <select class="prov" name="addr_province"></select>
                                    <select class="city" disabled="disabled" name="addr_city"></select>
                                    <select class="dist" disabled="disabled" name="addr_county"></select>
                                </div>
                                <span id="newcity"></span>
                                <span id="newcounty"></span>
                                <div id="error">
                                    <td colspan='2'>{{session("info")}}
                                        @if (count($errors) > 0)
                                        <ul style='font:14px  宋体;color: rgba(222, 36, 14, 0.87);'>

                                            @foreach ($errors->all() as $error)
                                            <img style="float:left;" src="{{ asset('/dist/home/images/Cerror.jpg') }}"> <li>{{$error}}</li>
                                            @endforeach

                                        </ul>
                                        @endif
                                    </td>
                                </div>
                            </div>
                            <div class="col-xs-12">
                                <span class="span_style" id="">详细地址</span>
                                <input class="input_style" type="text" name="addr_detail" id="address" value="" placeholder="&nbsp;&nbsp;请输入您的详细地址" />
                            </div>
                            <div class="col-xs-12">
                                <span class="span_style" id="">邮政编号</span>
                                <input class="input_style" type="text" name="addr_postcode" id="number_this" value="" placeholder="&nbsp;&nbsp;请输入您的邮政编号" />
                            </div>
                            <div class="col-xs-12">
                                <span class="span_style span_sty" id="">姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名</span>
                                <input class="input_style" type="text" name="addr_consignee" id="name_" value="" placeholder="&nbsp;&nbsp;请输入您的姓名" />
                            </div>
                            <div class="col-xs-12">
                                <span class="span_style" id="">手机号码</span>
                                <input class="input_style" type="text" name="addr_tel" id="phone" value="" placeholder="&nbsp;&nbsp;请输入您的手机号码" />
                            </div>
                            <div class="col-xs-12">
                                <input class="btn_remove" type="button" id="" onclick="javascript:onclick_close();" value="取消" />
                                <input type="submit" class="sub_set" id="sub_setID" value="提交" />
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <div class="user-main">
                <div class="addr-box"><h1>收货地址</h1>
                    @foreach ($address as $addr)
                    <div>
                        <div class="addr">
                            {{$addr->addr_consignee}}，&nbsp; {{$addr->addr_province}}&nbsp;{{$addr->addr_city}}&nbsp;{{$addr->addr_county}}&nbsp;{{$addr->addr_detail}}&nbsp;，{{$addr->addr_postcode}}&nbsp;，{{$addr->addr_tel}}
                            <div>
                                <form action="/address/{{$addr->id}}/status">
                                    @if($addr->addr_status !== 1)
                                    <input style="background-color: #8cc657; color: white" type='submit' class="shou" value="设为默认地址" >
                                    @else
                                    <input style="background-color: #8cc657; color: white" type='button' value="默认地址">
                                    @endif
                                    {{--<input  type="button" class="shou" name="checked"  onclick="status();"/>--}}
                                </form>
                            </div>
                        </div>
                        <div class="edde">
                            <a   class="action-edit shou" cname="kk{{$addr->id}}" data-monitor="user_address_editor"  title="编辑" >编辑</a>
                            ｜
                            <a class="action-del" data-monitor="user_address_delete" id="del" title="删除" onclick="javascript:onclick_remove(this);" href="/address/delete/{{$addr->id}}">删除</a>
                        </div>
                    </div>
                    <div class="sai"></div>
                    {{--隐藏--}}
                    <div class="mod-consignee-info" data-token="f4d9cb">
                        <!--I NEED-->
                        <form action="/address/{{$addr->id}}/edit" method="post">
                            <input type="hidden" name="_token" value="{{  csrf_token()}}"/>
                            <div style="display: none;"  class="consignee-add kk{{$addr->id}}" >
                                <div class="add-row">
                                    <label class="consignee-add-label" for="consignee_add_realname">
                                        <b>*</b>收货人姓名 </label>
                                    <input value="{{$addr->addr_consignee}}" name="addr_consignee"  class="consignee-add-text" placeholder="收货人姓名" type="text"></div>
                                <div class="add-row m-t-10">
                                    <div class="consignee-add-label" for="consignee_add_province">
                                        <b>*</b>地址 </div>
                                    <div class="city_edit_{{$addr->id}}">
                                        <select class="prov" name="addr_province">

                                        </select>
                                        <select class="city" disabled="disabled" name="addr_city"></select>
                                        <select class="dist" disabled="disabled" name="addr_county"></select>
                                    </div>
                                    <textarea  class="consignee-add-address" name="addr_detail" placeholder="{{$addr->addr_detail}}" >{{$addr->addr_detail}}</textarea></div>
                                <div class="add-row m-t-10">
                                    <label class="consignee-add-label" for="consignee_add_postcode">邮政编码</label>
                                    <input name="addr_postcode" class="consignee-add-text"  value="{{$addr->addr_postcode}}" placeholder="6位邮政编码" type="text"></div>
                                <div class="add-row m-t-10">
                                    <label class="consignee-add-label" for="consignee_add_mobile">
                                        <b>*</b>手机号码 </label>
                                    <input value="{{$addr->addr_tel}}" name="addr_tel"  class="consignee-add-text" placeholder="11位手机号" type="text"></div>
                                <div class="add-row m-t-10">
                                    <p class="m-t-20">
                                        <input type='submit' class="mod-btn-green shou" value="保存" >
                                        <input type='button' class="mod-btn-gray shou cancel" value="取消">
                                    </p>
                                </div>
                            </div>
                        </form>
                        <!--I NEED-->
                    </div>
                    @endforeach
                    
                    <div class="Caddress">
                        <div class="open_new" style="width: 1000px;margin-right: 60px;">
                            <button style="margin-right: 860px;" class="open_btn shou" onclick="javascript:onclick_open();">使用新地址</button>

                        </div>
                        <div id="error">
                            <td colspan='2'>{{session("info")}}
                                @if (count($errors) > 0)
                                <ul style='font:14px  宋体;color: rgba(222, 36, 14, 0.87);'>

                                    @foreach ($errors->all() as $error)
                                    <img style="float:left;" src="{{ asset('/dist/home/images/Cerror.jpg') }}"> <li>{{$error}}</li>
                                    @endforeach
                                </ul>
                                @endif
                            </td>
                        </div>
                    </div>
                </div>
                
                <!-- 搜索区域开始 -->
                <div class="shade">
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
@section('pluginscript')
<script type="text/javascript" src="{{  asset('/dist/home/js/City/jQuery.js') }}"></script>
<script type="text/javascript" src="{{  asset('/dist/home/js/City/jquery.cityselect.js') }}"></script>
<script>
    $('.city_2').citySelect({prov: "北京", nodata: "none"});
    @foreach ($address as $addr)
    $('.city_edit_{{$addr->id}}').citySelect({prov: "{{$addr->addr_province}}", city:"{{$addr->addr_city}}", dist:"{{$addr->addr_county}}", nodata: "none"});
    @endforeach
</script>
<script type="text/javascript">
$(function() {
    var region = $("#region");
    var address = $("#address");
    var number_this = $("#number_this");
    var name = $("#name_");
    var phone = $("#phone");
    $("#sub_setID").click(function() {
        var input_out = $(".input_style");
        for (var i = 0; i <= input_out.length; i++) {
            if ($(input_out[i]).val() == "") {
                $(input_out[i]).css("border", "1px solid red");
                return false;
            } else {
                $(input_out[i]).css("border", "1px solid #cccccc");
            }
        }
    });
    var span_momey = $(".span_momey");
    var b = 0;
    for (var i = 0; i < span_momey.length; i++) {
            b += parseFloat($(span_momey[i]).html());
    }
    var out_momey = $(".out_momey");
    out_momey.html(b);
    $(".shade_content").hide();
    $(".shade").hide();
    $('.nav_mini ul li').hover(function() {
            $(this).find('.two_nav').show(100);
    }, function() {
            $(this).find('.two_nav').hide(100);
    })
    $('.left_nav').hover(function() {
            $(this).find('.nav_mini').show(100);
    }, function() {
            $(this).find('.nav_mini').hide(100);
    })
    $('#jia').click(function() {
            $('input[name=num]').val(parseInt($('input[name=num]').val()) + 1);
    })
    $('#jian').click(function() {
            $('input[name=num]').val(parseInt($('input[name=num]').val()) - 1);
    })
    $('.Caddress .add_mi').click(function() {
            $(this).css('background', 'url("/dist/home/images/a/mail_1.jpg") no-repeat').siblings('.add_mi').css('background', 'url("/dist/home/images/a/mail.jpg") no-repeat')
    })
})
var x = Array();

function func(a, b) {
    x[b] = a.html();
    alert(x)
    a.css('border', '2px solid #f00').siblings('.min_mx').css('border', '2px solid #ccc');
}

function onclick_close() {
    var shade_content = $(".shade_content");
    var shade = $(".shade");
    if (confirm("确认关闭么！此操作不可恢复")) {
        shade_content.hide();
        shade.hide();
    }
}

function onclick_open() {
    $(".shade_content").show();
    $(".shade").show();
    var input_out = $(".input_style");
    for (var i = 0; i <= input_out.length; i++) {
        if ($(input_out[i]).val() != "") {
            $(input_out[i]).val("");
        }
    }
}

function onclick_remove(r) {
    if (confirm("确认删除么！此操作不可恢复")) {
        var out_momey = $(".out_momey");
        var input_val = $(r).parent().prev().children().eq(1).val();
        var span_html = $(r).parent().prev().prev().children().html();
        var out_add = parseFloat(input_val).toFixed(2) * parseFloat(span_html).toFixed(2);
        var reduce = parseFloat(out_momey.html()).toFixed(2) - parseFloat(out_add).toFixed(2);
        console.log(parseFloat(reduce).toFixed(2));
        out_momey.text(parseFloat(reduce).toFixed(2))
        $(r).parent().parent().remove();
    }
}
</script>
<script>
$(function() {
    $('.action-edit').click(function() {
        $('.consignee-add').slideUp();
        var c = $(this).attr('cname');
        $("." + c).slideDown();
    });
});
$(function() {
    $(".cancel").click(function() {
        $(".consignee-add").slideUp("normal");
    });
});
</script>
@endsection